home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / Target Acquisition Manager / Source / source / LClipPicture.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  3.1 KB  |  123 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    LClipPicture.cp                   ©1993-1998 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    Displays a 'PICT' resource
  6. //
  7. //    LClipPicture stores the ID of a PICT resource as a member variable, and
  8. //    always calls GetPicture() to get a Handle to the picture. It purposely
  9. //    does not release the PICT resource when deleted, since other LClipPicture
  10. //    views may be using the same picture. For example, you might use the
  11. //    same picture as a background or graphic element in multiple windows.
  12. //
  13. //    If you are concerned about the memory used by the PICT resource, mark
  14. //    it as purgeable in your resource file.
  15.  
  16. #ifdef PowerPlant_PCH
  17. #include PowerPlant_PCH
  18. #endif
  19.  
  20. #include "LClipPicture.h"
  21. #include <LStream.h>
  22. #include <UDrawingState.h>
  23.  
  24. #include <ToolUtils.h>
  25.  
  26. PP_Begin_Namespace_PowerPlant
  27.  
  28.  
  29. // ---------------------------------------------------------------------------
  30. //    • LClipPicture                                Default Constructor          [public]
  31. // ---------------------------------------------------------------------------
  32.  
  33. LClipPicture::LClipPicture()
  34. {
  35.     mPICT = nil;
  36. }
  37.  
  38.  
  39. // ---------------------------------------------------------------------------
  40. //    • LClipPicture(const LClipPicture&)                Copy Constructor          [public]
  41. // ---------------------------------------------------------------------------
  42.  
  43. LClipPicture::LClipPicture(
  44.     const LClipPicture&        inOriginal)
  45.     
  46.     : LView(inOriginal)
  47. {
  48.     mPICT = inOriginal.mPICT;
  49. }
  50.  
  51.  
  52. // ---------------------------------------------------------------------------
  53. //    • LClipPicture(LStream*)                        Stream Constructor      [public]
  54. // ---------------------------------------------------------------------------
  55.  
  56. LClipPicture::LClipPicture(
  57.     LStream*    inStream)
  58.     
  59.     : LView(inStream)
  60. {
  61.     mPICT = nil;
  62. }
  63.  
  64. // ---------------------------------------------------------------------------
  65. //    • SetPicture
  66. // ---------------------------------------------------------------------------
  67.  
  68. void
  69. LClipPicture::SetPicture(PicHandle inPict)
  70. {
  71.     if (mPICT != nil)
  72.         DisposeHandle((Handle)mPICT);
  73.     
  74.     mPICT = inPict;
  75.  
  76.     if (mPICT != nil)
  77.     {
  78.         Rect    picFrame = (**mPICT).picFrame;
  79.         
  80.         ResizeImageTo((picFrame.right - picFrame.left) * 4,
  81.                       (picFrame.bottom - picFrame.top) * 4, false);
  82.     }
  83.     
  84.     Refresh();
  85. }
  86.  
  87. // ---------------------------------------------------------------------------
  88. //    • DrawSelf                                                       [protected]
  89. // ---------------------------------------------------------------------------
  90. //    Draw a Picture
  91.  
  92. void
  93. LClipPicture::DrawSelf()
  94. {
  95.         // If Picture resource exists, draw it. Otherwise, fill the
  96.         // Frame with a light gray pattern and a one-pixel border.
  97.         
  98.     if (mPICT != nil)
  99.     {
  100.         SDimension32    imageSize;
  101.         GetImageSize(imageSize);
  102.         
  103.         Rect    pictureBounds;
  104.         pictureBounds.left   = 0;
  105.         pictureBounds.top    = 0;
  106.         pictureBounds.right  = (SInt16) imageSize.width;
  107.         pictureBounds.bottom = (SInt16) imageSize.height;
  108.         
  109.         ::DrawPicture(mPICT, &pictureBounds);
  110.     } 
  111.     else
  112.     {
  113.         Rect    frame;
  114.         CalcLocalFrameRect(frame);
  115.         ::PenNormal();
  116.         ::FillRect(&frame, &UQDGlobals::GetQDGlobals()->ltGray);
  117.         ::FrameRect(&frame);
  118.     }
  119. }
  120.  
  121.  
  122. PP_End_Namespace_PowerPlant
  123.